"use strict";
cc._RF.push(module, 'fa748bCfMNLDJcQjZa78muh', 'Giftbar');
// Texture/gift/Giftbar.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var storage_1 = require("../../Script/SdkTools/storage");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
// 游戏启动监听场景值
console.log("游戏启动监听场景值 window['tt']:", typeof window['tt']);
if (typeof window['tt'] == 'object') {
    console.log('tt init success');
    var tt = window['tt'];
    tt.onShow(function (res) {
        console.log('启动参数：', res.query);
        console.log('来源信息：', res.refererInfo);
        console.log('场景值：', res.scene);
        console.log('启动场景字段：', res.launch_from, ', ', res.location);
        cc.sys.localStorage.setItem('isLaunchFromSidebar', 'false');
        if ((res.launch_from == 'homepage' && res.location == 'sidebar_card') ||
            res.scene == '021036') {
            cc.sys.localStorage.setItem('isLaunchFromSidebar', 'true');
        }
        if ((res.launch_from == 'game_room' && res.location == 'game_list') ||
            res.scene == '021036') {
            cc.sys.localStorage.setItem('isLaunchFromSidebar', 'true');
        }
        console.log('isLaunchFromSidebar:' + cc.sys.localStorage.getItem('isLaunchFromSidebar'));
    });
}
var Giftbar = /** @class */ (function (_super) {
    __extends(Giftbar, _super);
    function Giftbar() {
        var _this_1 = _super !== null && _super.apply(this, arguments) || this;
        _this_1.panelNode = null;
        _this_1.giftLabel = null;
        _this_1.giftNode = null;
        _this_1.tt = null;
        return _this_1;
    }
    Giftbar.prototype.start = function () {
        cc.game.addPersistRootNode(this.node);
        //非字节平台隐藏sliderbar
        this.initTT();
        this.initGiftbar();
    };
    Giftbar.prototype.initGiftbar = function () {
        this.giftNode.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.giftNode.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
        this.giftNode.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
    };
    Giftbar.prototype.onTouchStart = function (event) { };
    Giftbar.prototype.onTouchMove = function (event) {
        var size = this.node.getContentSize();
        var giftSize = this.giftNode.getContentSize();
        var to = new cc.Vec3(event.getLocationX() - size.width / 2, event.getLocationY() - size.height / 2);
        if (to.x < -size.width / 2 + giftSize.width / 2) {
            to.x = -size.width / 2 + giftSize.width / 2;
        }
        if (to.y < -size.height / 2 + giftSize.height / 2) {
            to.y = -size.height / 2 + giftSize.height / 2;
        }
        if (to.x > size.width / 2 - giftSize.width / 2) {
            to.x = size.width / 2 - giftSize.width / 2;
        }
        if (to.y > size.height / 2 - giftSize.height / 2) {
            to.y = size.height / 2 - giftSize.height / 2;
        }
        this.giftNode.position = to;
    };
    Giftbar.prototype.onTouchEnd = function (event) { };
    Giftbar.prototype.initTT = function () {
        if (typeof window['tt'] == 'undefined') {
            this.node.active = false;
            return;
        }
        var _this = this;
        var _giftLabel = this.giftLabel;
        this.tt = window['tt'];
        // 检查是否存在侧边栏
        this.tt.checkScene({
            scene: 'sidebar',
            success: function (res) {
                console.log('check scene success: ', res.isExist);
                //成功回调逻辑
                if (!res.isExist) {
                    // 是否展示领奖入口
                    _this.node.active = false;
                }
                else {
                    _this.node.active = true;
                    // 判断是否是从侧边栏进入
                    if (cc.sys.localStorage.getItem('isLaunchFromSidebar') == 'true') {
                        if (cc.sys.localStorage.getItem('LaunchFromSidebarGift') == 'true') {
                            _giftLabel.string = '奖励已领取';
                        }
                        else {
                            _giftLabel.string = '领取奖励';
                        }
                    }
                    else {
                        _giftLabel.string = '侧边栏领奖';
                    }
                }
            },
            fail: function (res) {
                //失败回调逻辑
                console.log('check scene fail:', res);
            },
        });
    };
    Giftbar.prototype.clickSilderBar = function () {
        console.log('clickSliderBar');
        if (this.panelNode.active == false) {
            this.panelNode.active = true;
            cc.director.pause();
        }
        else {
            this.panelNode.active = false;
            cc.director.resume();
        }
    };
    Giftbar.prototype.backSilderBar = function () {
        console.log('backSliderBar');
        var btnText = this.giftLabel.string;
        if (btnText == '侧边栏领奖') {
            console.log('45789');
            // 返回侧边栏
            this.tt.navigateToScene({
                scene: 'sidebar',
                success: function (res) {
                    // 跳转成功回调逻辑
                    console.log('navigate to scene success', res);
                },
                fail: function (res) {
                    // 跳转失败回调逻辑
                    console.log('navigate to scene fail: ', res);
                },
            });
        }
        else if (btnText == '领取奖励') {
            if (cc.sys.localStorage.getItem('LaunchFromSidebarGift') == 'true') {
                this.giftLabel.string = '奖励已领取';
                return;
            }
            // 领取奖励
            console.log('领取侧边栏奖励');
            storage_1.default.Instance.setEnergy(storage_1.default.Instance.nowEnery + 2);
            //cc.sys.localStorage.setItem("no_ad_time", new Date().getTime() + 10 * 60 * 1000); // 十分钟免广告
            cc.sys.localStorage.setItem('LaunchFromSidebarGift', 'true');
            this.giftLabel.string = '奖励已领取';
            console.log('领取侧边栏奖励成功');
        }
        else if (btnText == '奖励已领取') {
            console.log('奖励已领取');
        }
    };
    __decorate([
        property(cc.Node)
    ], Giftbar.prototype, "panelNode", void 0);
    __decorate([
        property(cc.Label)
    ], Giftbar.prototype, "giftLabel", void 0);
    __decorate([
        property(cc.Node)
    ], Giftbar.prototype, "giftNode", void 0);
    Giftbar = __decorate([
        ccclass
    ], Giftbar);
    return Giftbar;
}(cc.Component));
exports.default = Giftbar;

cc._RF.pop();